<!doctype html>
<html>
<head>
    <title>BoxWithLight</title>
    <meta charset="utf-8">

    <script id="shader-fs" type="x-shader/x-fragment">
            #ifdef GL_ES
            precision highp float;
            #endif

            //uniform vec3 og_sunPosition;
            uniform vec3 u_color;

            varying float vLightWeighting;
            varying vec3 vColor;

            void main(void) {
                //gl_FragColor = vec4(u_color * vLightWeighting,1.0);
                vec3 dd = u_color;
                gl_FragColor = vec4(vColor,1.0);
            }
        </script>

    <!-- Vertex Shader //-->
    <script id="shader-vs" type="x-shader/x-vertex">
            attribute vec3 aVertexPosition;
            attribute vec3 aNormal;

            uniform mat4 og_modelViewPerspectiveMatrix;
            uniform mat4 og_modelViewMatrixRelativeToEye;
            uniform mat4 og_modelViewMatrix;
            uniform mat4 og_modelMatrix;
            uniform mat4 og_viewMatrix;
            uniform mat4 og_perspectiveMatrix;
            uniform mat4 og_normalMatrix;

            uniform vec3 og_sunPosition;        //lightPosition

            varying float vLightWeighting;
            varying vec3 vColor;

            void main(void) {

                //vec3 normal = normalize((og_normalMatrix * vec4(aNormal,1.0)).xyz);
                vec3 normal = normalize(aNormal);
                vColor = normal;

                vec3 uAmbientColor = vec3(0.3,0.3,0.3);
                vec3 uLightColor = vec3(0.5,0.5,0.0);

                vec4 position = og_modelViewMatrix * vec4(aVertexPosition,1.0);
                vec4 lightPosition = og_modelViewMatrix * vec4(og_sunPosition,1.0);

                float directionalLightWeighting = max(dot(normal, og_sunPosition - aVertexPosition), 0.0);
                vLightWeighting = directionalLightWeighting;
                vColor = uAmbientColor + vColor * vLightWeighting;

                gl_Position = og_modelViewPerspectiveMatrix * vec4(aVertexPosition,1.0);
            }
        </script>

    <!--<script src="Source/thirdparty/gl-matrix.js"></script>-->
    <script src="../Source/thirdparty/webgl-utils.js"></script>

</head>
<body>
<canvas id="canvas" width="680" height="680"></canvas>
<script data-main="js/03_BoxWithLight" src="../require.js"></script>
</body>
</html>